package com.inspur.cmis.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.inspur.cmis.mapper.ClientManagerMapper;
import com.inspur.cmis.pojo.ClientManager;
import com.inspur.cmis.service.ClientManagerService;
import com.inspur.cmis.util.ExcelBean;
import com.inspur.cmis.util.ExportExcelUtil;
@Service
public class ClientManagerImpl implements ClientManagerService{
	@Autowired
	private ClientManagerMapper clientMgrMapper;
	
	
	/**
	 * 查询客户经理信息
	 */
	public List<ClientManager> getClientMgrList(HashMap<String, Object> map){
		return clientMgrMapper.getClientMgrList(map);
	}
	
	
	/**
	 * 删除客户经理信息
	 */
	public void deleteMgr(String mgrId[]){
		clientMgrMapper.deleteMgr(mgrId);
	}
	/**
	 * 根据id获取客户经理级别信息
	 */
	public ClientManager getClientMgrInfo(String mgrId){
		return clientMgrMapper.getClientMgrInfo(mgrId);
	}
	/**
	 * 添加客户经理信息
	 */
	public void clientMgrAdd(ClientManager clientMgr){
		clientMgrMapper.clientMgrAdd(clientMgr);
	}


	/**
	 *
	 * 查询客户经理信息-导出查询
	 */
	public List<HashMap<String,Object>> getClientMgrListForExp(HashMap<String, Object> map){
		return clientMgrMapper.getClientMgrforExport(map);
	}
	/**
	 * 导出客户经理信息
	 */
	public XSSFWorkbook exportExcelInfo(HashMap<String, Object> map) throws Exception{
		//根据条件查询数据
				List<HashMap<String,Object>> mgrList = clientMgrMapper.getClientMgrforExport(map);
				//System.out.println(list);
				List<ExcelBean> excel = new ArrayList();
				Map<Integer,List<ExcelBean>> excelMmap = new LinkedHashMap<>();
				//设置标题栏
				excel.add(new ExcelBean("客户经理编号","userId",0));
				excel.add(new ExcelBean("姓名","userName",0));
				excel.add(new ExcelBean("性别", "sex", 0));
				excel.add(new ExcelBean("身份证号","IDCard",0));
				excel.add(new ExcelBean("出生日期","birthday",0));
				excel.add(new ExcelBean("客户经理等级","levl", 0));
				excel.add(new ExcelBean("机构","unit",0));
				excel.add(new ExcelBean("部门","dept",0));
				excelMmap.put(0,excel);
				String sheetName = "客户经理信息表";
				//调用ExcelUtil方法
				XSSFWorkbook xssfWorkbook = ExportExcelUtil.createExcelFile(ClientManager.class, mgrList, excelMmap, sheetName);
				System.out.println(xssfWorkbook);
				return xssfWorkbook;

	}


	/**
	 * 批量导入客户经理信息
	 */
	public void importClientMgrList(List<ClientManager> clientMgrList) {
		clientMgrMapper.importClientMgrList(clientMgrList);
		
	}


}
